#ifndef _VAD_INST_H
#define _VAD_INST_H
#include<thread>
#include"../data/data.h"
#include "../buffer/buffer.h"
#include "../../api/api.h"
#include "../reporter/reporter.h"
#include "recoProxy_vad.h"
using namespace speech;

//typedef shared_ptr<data>    sData;
typedef shared_ptr<data>    sData;
typedef buffer<sData>*       vadBuffer;
typedef shared_ptr< buffer<sData> >      sVadBuffer;
typedef shared_ptr<thread>  sThread;
//typedef shared_ptr<speech::reporter> sReporter;
class vadInst{
public:
	vadInst(vadOptions* pOptions,int iType, vadCbUtil* pCbUtil)
		:_iType(iType),
		_pOptions(pOptions),
		_pCbUtil(pCbUtil)
		//_pCbFunc(pCbFunc),
		//_pCbCloseFunc(pCbCloseFunc),
		//_pCbObj(pCbObj)
	{
		_pVadBuffer = make_shared< buffer<sData> >();
		memset(&_var,0,sizeof(vadVars));
		//printf("vad Inst cb Pointer %p \n ", _pCbObj);
	}
	virtual ~vadInst(){}
	//init vad instance
	virtual void * init()=0;
	//virtual void   reset()=0;
	virtual void   close()=0;
	virtual void   writeBuffer(char*, int)=0;
	sVadBuffer getBuffer(){return _pVadBuffer;}
	//virtual release(void* pVadInst)=0;
	vadCallBackFunc getCbFunc() {return _pCbUtil->_vadCbFunc;}
	CBINST getCbObj() { return _pCbUtil->_vadCbInst;}
	vadCloseCb getCloseCbFunc(){ return _pCbUtil->_vadCbCloseFunc;}
	vadCbUpdateTime getCbUpdateTimeFunc() { return  _pCbUtil->_vadCbUpdateTimeFunc;}
	//sReporter getReporter() { return _sReporter;}
	vadOptions* getOptions() { return _pOptions;}
protected:
	void run();
    const static int VAD_BUFF_LEN = 16000;
	const static int PCM_BUFF = 640;
	vadVars          _var;
private:
	//vadBuffer        _pVadBuffer;
	sVadBuffer        _pVadBuffer;
	int              _iType;
	vadOptions*      _pOptions;
	vadCbUtil*       _pCbUtil;
	//vadCallBackFunc  _pCbFunc;
	//vadCloseCb       _pCbCloseFunc;
	//CBINST           _pCbObj;
};
#endif
